//
//  CHComplaintDetailController.m
//  CarFile
//
//  Created by 陈浩 on 2017/7/31.
//  Copyright © 2017年 陈浩. All rights reserved.
//

#import "CHComplaintDetailController.h"
#import "CHPhotosView.h"
@interface CHComplaintDetailController ()
{
    UILabel *titleLabel;         //  企业名
    UILabel *timeLabel;
    UILabel *phoneLabel;
    UIImageView *iconImgView;      //   头像
    UILabel *valuatevalueLabel;
    UILabel *evaluatedetailsLabel;      //  用户反馈
    UILabel *supervisevalueLabel;       //  企业回复
    UIImageView *picImgView;
    UIView *bgView;
    NSDictionary *dict;
    CHPhotosView *photosView;
}
@end

@implementation CHComplaintDetailController


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"投诉详情";
    self.view.backgroundColor = [UIColor whiteColor];
    
    
//    [BQActivityView showActiviTy];


    [self setupUI];
}


//
//-(void)getData{
//    
//     CHComplainListModel *model = self.complainListFrm.model;
//    
//
//    NSMutableDictionary *params = [NSMutableDictionary dictionary];
//    params[@"areaid"] =  self.areaid;
//    params[@"usertype"] = [Util getValue:@"usertype"];
//    params[@"user"] = USER;
//    params[@"sign"] = [DESCript encrypt:model.evaluateid encryptOrDecrypt:kCCEncrypt key:@"G*GL%#C_"];
//    params[@"evaluateid"] = model.evaluateid;
//
//    [[Globle getInstance].service requestWithServiceName:@"lcipappgovcomplaintdetails" params:params httpMethod:@"POST" resultIsDictionary:YES completeBlock:^(id result) {
//        [BQActivityView hideActiviTy];
//        
//        NSLog(@"投诉详情%@",result);
//        if ([result[@"code"] isEqualToString:@"1"]) {
//           NSDictionary * dict1 = result[@"data"];
//            dict = dict1;
//           
//            [self setupUI];
//            
//        }
//        
//    }];
//    
//}

-(void)setupUI{
    
    
    
    CHComplainListModel *model = self.complainListFrm.model;
    titleLabel = [[UILabel alloc] initWithFrame:self.complainListFrm.titleFrm];
    titleLabel.text = model.company;
    titleLabel.numberOfLines = 0;
    titleLabel.textColor =  [UIColor colorWithHexString:@"168bce" alpha:1.0f];
    titleLabel.font = [UIFont systemFontOfSize:16];
    [self.view addSubview:titleLabel];

    
    timeLabel = [[UILabel alloc] initWithFrame:self.complainListFrm.timeFrm];
    timeLabel.text = model.complainttime;
    timeLabel.textAlignment = NSTextAlignmentRight;
    timeLabel.textColor = [UIColor colorWithHexString:@"666666" alpha:1.0f];
    timeLabel.font = [UIFont systemFontOfSize:12];
    [self.view addSubview:timeLabel];
 
    
    iconImgView = [[UIImageView alloc] initWithFrame:self.complainListFrm.iconFrm];
    iconImgView.image = [UIImage imageNamed:@"car_icon"];
    [self.view addSubview:iconImgView];

    
    phoneLabel = [[UILabel alloc] initWithFrame:self.complainListFrm.phoneFrm];
    phoneLabel.font = [UIFont systemFontOfSize:13];
    phoneLabel.text = [model.mobilephone stringByReplacingCharactersInRange:NSMakeRange(3, 4) withString:@"****"];
    phoneLabel.textColor = [UIColor colorWithHexString:@"666666" alpha:1.0f];
    [self.view addSubview:phoneLabel];


//    投诉内容
    evaluatedetailsLabel = [[UILabel alloc] initWithFrame:self.complainListFrm.evaluatedetailsFrm];
    evaluatedetailsLabel.text = model.evaluatedetails;
    evaluatedetailsLabel.numberOfLines = 0;
    evaluatedetailsLabel.font = [UIFont systemFontOfSize:14];
    [self.view addSubview:evaluatedetailsLabel];

    photosView = [[CHPhotosView alloc] initWithFrame:self.complainListFrm.photosViewFrm];
    photosView.pic_urls = [model.complainaccordimg componentsSeparatedByString:@","];
    [self.view addSubview:photosView];
    
    CGFloat  currentHeight = 0;
   
    if (model.complainaccordimg.length >0) {
        
        currentHeight = CGRectGetMaxY(photosView.frame);
    }else{
        currentHeight = CGRectGetMaxY(evaluatedetailsLabel.frame);
    }

    
    if (model.supervisevalue.length >0) {
        
        bgView = [[UIView alloc] initWithFrame:self.complainListFrm.bgViewFrm];
        bgView.backgroundColor = [UIColor colorWithRed:244/255.0 green:244/255.0 blue:244/255.0 alpha:1.0f];
        [self.view addSubview:bgView];
        
        //    投诉反馈内容
        supervisevalueLabel = [[UILabel alloc] initWithFrame:self.complainListFrm.supervisevalueFrm];
        supervisevalueLabel.text = [NSString stringWithFormat:@"督办意见：%@",model.supervisevalue];
        
        supervisevalueLabel.textColor = [UIColor colorWithHexString:@"888888" alpha:1.0f];
        supervisevalueLabel.font = [UIFont systemFontOfSize:12];
        supervisevalueLabel.numberOfLines = 0;
        [bgView addSubview:supervisevalueLabel];
        
        currentHeight = CGRectGetMaxY(bgView.frame);
    }

    
    
    CGSize maxSize = CGSizeMake(UIScreenW -2*10, MAXFLOAT);
    NSDictionary *attr = @{NSFontAttributeName:[UIFont systemFontOfSize:12]};
    CGSize valuatevalueSize = [self boundingRectWithSize:maxSize attributes:attr text:[NSString stringWithFormat:@"企业回复：%@",model.valuatevalue]];
  
    UIView *bgView1 = [[UIView alloc] initWithFrame:CGRectMake(0, currentHeight +10, UIScreenW, valuatevalueSize.height+20)];
    bgView1.backgroundColor = [UIColor colorWithRed:244/255.0 green:244/255.0 blue:244/255.0 alpha:1.0f];
    [self.view addSubview:bgView1];
    
   
    valuatevalueLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, UIScreenW -20, valuatevalueSize.height)];
    valuatevalueLabel.text = [NSString stringWithFormat:@"企业回复：%@",model.valuatevalue];
    valuatevalueLabel.textColor = [UIColor colorWithHexString:@"888888" alpha:1.0f];
    valuatevalueLabel.font = [UIFont systemFontOfSize:12];
    valuatevalueLabel.numberOfLines = 0;
    [bgView1 addSubview:valuatevalueLabel];

    
}


- (CGSize)boundingRectWithSize:(CGSize)maxSize attributes:(NSDictionary *)attr text:(NSString *)text
{
    return [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attr context:nil].size;
}


#pragma mark LongriseRouterDelegater代理回调方法
-(void)setParams:(id)obj block:(LongriseRouterBlock)block
{
    
    if (obj && [obj isKindOfClass:[NSMutableDictionary class]]) {
        
        NSMutableDictionary *dict = obj;
        self.areaid = dict[@"areaid"];
        self.complainListFrm = dict[@"complainListFrm"];
        
    }
}



@end
